﻿function view(bh)  //转到查看页面
{
    window.location.href = 'StuView.aspx?id=' + bh + '&page=stu';

}
function edit(bh)  //转到编辑页面
{
    $.ajax({
        type: "get",
        url: "Handler/PaperHandler.ashx?d=" + new Date().getMilliseconds() + "&type=edit&ID=" + bh,
        beforeSend: function (XMLHttpRequest) {
            //ShowLoading();
        },
        success: function (data, textStatus) {
            var obj = eval('(' + data.toString() + ')');

            $("#selectDep").attr("value", obj.DepID);
            $("#selectCourse").attr("value", obj.CourseID);
            $("#hdType").val("editsave");
            $("#hdID").val(bh);
            $("#txtPaperName").val(obj.PaperName);


            

            $("#txtStartDateTime").datetimebox("setValue", obj.startExamTime);
            $("#txtEndDateTime").datetimebox("setValue", obj.EndExamTime);

            //$("#txtStartDateTime").val(obj.startExamTime);
            //$("#txtEndDateTime").val(obj.EndExamTime);
            $("#txtExamTime").val(obj.ExamTime);
            $("#txtallowExamNum").val(obj.allowExamNum);
            $("#txtpassmark").val(obj.passMark);
            $("#txtJoinEmpID").val(obj.joinemps);
            var probleminfo = obj.ProblemInfo.split(",");
            $("#txtSingleNum").val(probleminfo[0].split(":")[1]);
            $("#txtSingleFen").val(probleminfo[0].split(":")[2]);
            $("#txtMultiNum").val(probleminfo[1].split(":")[1]);
            $("#txtMultiFen").val(probleminfo[1].split(":")[2]);
            $("#txtJudgeNum").val(probleminfo[2].split(":")[1]);
            $("#txtJudgeFen").val(probleminfo[2].split(":")[2]);
            $("#txtFillBlankNum").val(probleminfo[3].split(":")[1]);
            $("#txtFillBlankFen").val(probleminfo[3].split(":")[2]);
            $("#txtQuestionNum").val(probleminfo[4].split(":")[1]);
            $("#txtQuestionFen").val(probleminfo[4].split(":")[2]);


            $("input[name='txtExamTime']").attr("value", obj.ExamTime);
            $("input[name='txtallowExamNum']").attr("value", obj.allowExamNum);
            $("input[name='txtpassmark']").attr("value", obj.passMark);

            $("input[name='txtSingleNum']").attr("value", probleminfo[0].split(":")[1]);
            $("input[name='txtSingleFen']").attr("value", probleminfo[0].split(":")[2]);
            $("input[name='txtMultiNum']").attr("value", probleminfo[1].split(":")[1]);
            $("input[name='txtMultiFen']").attr("value", probleminfo[1].split(":")[2]);
            $("input[name='txtJudgeNum']").attr("value", probleminfo[2].split(":")[1]);
            $("input[name='txtJudgeFen']").attr("value", probleminfo[2].split(":")[2]);
            $("input[name='txtFillBlankNum']").attr("value", probleminfo[3].split(":")[1]);
            $("input[name='txtFillBlankFen']").attr("value", probleminfo[3].split(":")[2]);
            $("input[name='txtQuestionNum']").attr("value", probleminfo[4].split(":")[1]);
            $("input[name='txtQuestionFen']").attr("value", probleminfo[4].split(":")[2]);

            $('#dd').dialog('open').dialog('setTitle', '编辑试卷--' + obj.PaperName);

        },
        complete: function (XMLHttpRequest, textStatus) {
            //HideLoading();
        },
        error: function () {
            //请求出错处理
        }
    });

    //window.location.href = 'StuEdit.aspx?id=' + bh;

}
function add() {
    //$("#selectCourse").attr("value", obj.CourseID);
    $("#txtPaperName").val("");
    $("#txtStartDateTime").val("");
    $("#txtEndDateTime").val("");
    $("#txtExamTime").val("");
    $("#txtallowExamNum").val("");
    $("#txtpassmark").val("");
    $("#txtJoinEmpID").val("");

    $("#txtSingleNum").val("");
    $("#txtSingleFen").val("");
    $("#txtMultiNum").val("");
    $("#txtMultiFen").val("");
    $("#txtJudgeNum").val("");
    $("#txtJudgeFen").val("");
    $("#txtFillBlankNum").val("");
    $("#txtFillBlankFen").val("");
    $("#txtQuestionNum").val("");
    $("#txtQuestionFen").val("");

    $("#hdType").val("addsave");
    $('#dd').dialog('open').dialog('setTitle', '制定新试卷');
}

function save() {
    $('#ff').form('submit', {
        url: 'Handler/PaperHandler.ashx?d=' + new Date().getMilliseconds() + '&type=' + $("#hdType").val(),
        onSubmit: function () {
            return $(this).form('validate');
            // do some check  
            // return false to prevent submit;  
        },
        success: function (data) {
            if (data > 0) {
                $.messager.alert('操作结果', "执行成功，编号为：" + data, 'info');
                $('#dd').dialog('close')
            }
        }
    });
    // submit the form  
    //$('#ff').submit();  
    $('#tt').datagrid('reload');

    // $("#ff").submit();
}

function del(index) {  //删除操作
    $.messager.confirm('确认', '确认删除?', function (row) {
        if (row) {
            var selectedRow = $('#tt').datagrid('getSelected');  //获取选中行
            $.ajax({
                url: 'Handler/PaperHandler.ashx?type=del&ID=' + selectedRow.PaperID,
                //加了个type，作用是以后不管什么删除，都可以转到这个ashx中处理
                success: function () { $.messager.alert('操作结果', "删除成功，编号为：" + selectedRow.PaperID, 'info'); }
            });
            $('#tt').datagrid('deleteRow', index);
        }
    })
}
